package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.SupplierProxy;
	import vn.demand.dragon.view.SupplierListMediator;
	import vn.demand.dragon.view.SupplierSearchMediator;
	import vn.demand.dragon.view.components.SuppliersList;
	
	public class OpenSupplierListCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			if (facade.hasMediator(SupplierListMediator.NAME)) {
				TabManager.openTab(SuppliersList, SupplierListMediator.NAME);
				return;
			}
			var ui:SuppliersList = TabManager.openTab(SuppliersList, SupplierListMediator.NAME) as SuppliersList;
			//register Proxies
			var supplierProxy:SupplierProxy = facade.retrieveProxy(SupplierProxy.NAME) as SupplierProxy;

			if (supplierProxy == null) {
				supplierProxy = new SupplierProxy(SupplierProxy.NAME);
	            facade.registerProxy(supplierProxy);
			}
            supplierProxy.search();
            
            facade.registerMediator(new SupplierListMediator(ui));
            facade.registerMediator(new SupplierSearchMediator(SupplierSearchMediator.NAME, ui.searchForm));
        }
	}
}